package com.juphoon.mockdata.util;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

import java.io.IOException;

/**
 * @author juphoon
 * @date 2022/8/8
 */
public class XmlHelper {
    XmlMapper mapper;

    public XmlHelper() {
        mapper = new XmlMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    }

    public String toXml(Object object) throws IOException {
        return mapper.writeValueAsString(object);
    }

    public <T> T fromXml(String xml, Class<T> cls) throws IOException {
        return mapper.readValue(xml, cls);
    }

}
